package app.netant.book.fushu365;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class Fushu365Detail extends BaseDetail {

	public Fushu365Detail(String netSite) {
		super(netSite);
		this.preHref = "https://fushu365.com";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select("#page #p1 #p2 .pl .pl1 .cont h1");
		if(parts.size()>0){
			String title = parts.get(0).text();
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select("#page #p1 #p2 .pl .pl1 .cont ul li");
		for(int i=0;i<parts.size();i++){
			String tags = parts.get(i).text();
			int idx = tags.indexOf("：");
			if(idx>0){
				String tagName = tags.substring(0,idx).trim();
				String tagValue = tags.substring(idx+1).trim();
				System.out.println("【Tag】:"+tagName+"="+tagValue);
				this.entity.setTag(tagName, tagValue);
			}
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select("#page #p1 #p2 .pl .pl1 .cont dl p#xxinfo");
		if(parts.size()>0){
			String memo = parts.get(0).text();
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select("#page #p1 #p2 .pl .pl3 p a");
		if(parts.size()>0){
			String refer = parts.get(0).attr("href");
			if(refer.startsWith("/")){
				refer = this.preHref + refer;
			}
			System.out.println("【Refer】:"+refer);
			this.entity.setRefer(refer);
			
			Fushu365Detail detail = new Fushu365Detail(refer);
			String href = detail.stepHref();
			System.out.println("【Href】:"+href);
			this.entity.setDownPath(href);
		}
	}
	
	public String stepHref(){
		Elements parts = this.select("#page #p1 #p2 .d1 p a");
		if(parts.size()>0){
			String href = parts.get(0).attr("href");
			if(href.startsWith("../")){
				href = "https://fushu365.com/e/DownSys" + href.substring(2);
			}
			return href;
		}
		return null;
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select("#page #p1 #p2 .pl .pl1 h3 a");
		if(parts.size()>1){
			String type = parts.get(1).text();
			System.out.println("【Type】："+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		Fushu365Detail detail = new Fushu365Detail("https://fushu365.com/book/30928.html");
		detail.test();
	}



}
